
package simuri.uridb;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author fomy
 */

public class ComputeAprioriUri {
    
    public void AprioriInDb(String surfaceformfile)  {
         
       Connection con = DbConnection.getConnection();
       
      try{ 
        BufferedReader br = new BufferedReader(new FileReader(surfaceformfile));
        Statement stmt = con.createStatement();  
        String line,insert;
        while (( line = br.readLine()) != null){
            String[]split = line.split("\t");
            String uriname = "http://dbpedia.org/resource/"+split[0];

        // feeling uri_aprioriscores Table
            EdgeCount EC = new EdgeCount();
            try {
            double ingoing_edges = EC.getAprioriScore1(uriname, "http://dbpedia.org/sparql", null);
            System.out.println(uriname + "\t" + ingoing_edges );
            insert = "INSERT INTO uri_aprioriscores (uri_name,ingoing_edges) VALUES('" + uriname + "'," + ingoing_edges + ")";
            stmt.execute(insert); 
            }catch(Exception e){

                }
            }

            stmt.close();
            con.close();
        } catch (SQLException | IOException se) {
          System.out.println("SQL Fehler " + se.getMessage());
          se.printStackTrace(System.out);
        }
    }
    
}
